// pages/enterprise/listCont/listCont.js
import {
    ajaxPost,
    showToast
} from '../../../utils/util'
let app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        backShow: false, // 返回按钮
        userId: 0, // 用户id
        meetingCount: 0, // 他关注的场次
        collectVal: false, // 是否收藏
        is_unlock: 0, // 是否解锁图片简历
        is_invitation: 0, // 是否邀请参加招聘会
        resume_status: 0, // 1未处理 2有意向 3不合适
        resume_position_id: 0, // 简历添加记录ID
        remark: '', // 备注
        complaintShow: false, // 举报开关
        aid: '', //岗位id
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        console.log(options);
        if (options.type == 'resume' || options.type == 'code') {
            this.setData({
                userId: options.id,
                aid: options.aid,
                backShow: true
            })
            if (!!options.aid) {
                this.setData({
                    aid: options.aid
                })
            }
            if (options.type == 'code') {
                let data = {
                    token: wx.getStorageSync('token'),
                    user_id: options.id
                }
                ajaxPost('/authuser/scanResume', data, res => {
                    if (res.code == 0) {
                        showToast('text', '解锁成功')
                        this.getuserInfo()
                    } else {
                        showToast('text', res.msg)
                        this.getuserInfo()
                    }
                })
            } else {
                this.getuserInfo()
            }
        } else {
            this.setData({
                userId: options.id,
                aid: options.aid,
            })
            this.getuserInfo()
        }

    },
    /**
     * 获取学生信息
     */
    getuserInfo() {
        let data = {
            token: wx.getStorageSync('token'),
            user_id: this.data.userId
        }
        if (!!this.data.aid) {
            data.position_id = this.data.aid
        }
        ajaxPost('/authuser/xxuserinfo', data, res => {
            if (res.code == 0) {
                this.setData({
                    XXuserSource: res.data,
                    educationSource: res.data.education_exp,
                    meetingCount: res.data.follow_meeting_count,
                    workSource: res.data.intention_list,
                    userSource: res.data.user_info,
                    collectVal: res.data.is_collection == 0 ? false : true,
                    is_unlock: res.data.is_unlock,
                    resume_status: res.data.resume_status,
                    is_invitation: res.data.is_invitation,
                    resume_position_id: res.data.resume_position_id,
                    remark: res.data.remark
                })
            }
        })
    },
    /**
     * 分享
     */
    onShareAppMessage() {
        return {
            title: `这里有一份优质简历推荐给你 点击看看吧`,
            path: `/pages/share/share?identity=enterprise&type=resume&shareId=${this.data.userId}`,
            success: function (res) {
                showToast('text', '分享成功')
            }
        }
    },
    /**
     * 收藏按钮切换
     */
    collectClick() {
        let data = {
            token: wx.getStorageSync('token'),
            user_id: this.data.userId
        }
        ajaxPost('/authuser/collectionuser', data, res => {
            if (res.code == 0) {
                if (!this.data.collectVal) {
                    showToast('text', '关注成功')
                } else {
                    showToast('text', '取消关注成功')
                }
                this.setData({
                    collectVal: !this.data.collectVal
                })
            } else {
                showToast('text', res.msg)
            }
        })
    },
    /**
     * 图片查看
     */
    previewImage: function (event) {
        if (!this.data.is_unlock) {
            return false
        }
        let src = event.currentTarget.dataset.src; //获取data-src
        let imgList = []
        imgList[0] = event.currentTarget.dataset.list; //获取data-list
        //图片预览
        wx.previewImage({
            current: src, // 当前显示图片的http链接
            urls: imgList // 需要预览的图片http链接列表
        })
    },
    /**
     * 解锁简历图片
     */
    unlockFn() {
        if (app.globalData.companState == 0) {
            wx.navigateTo({
                url: `/pages/web/web?url=${app.globalData.WEBURL}/h5/index/weiRenZhengJianLi`
            })
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            user_id: this.data.userId
        }
        ajaxPost('/authuser/unlockresume', data, res => {
            if (res.code == 0) {
                showToast('text', '解锁成功')
                this.setData({
                    is_unlock: 1,
                    resume_status: 1,
                    resume_position_id: res.data.resume_position_id
                })
            } else {
                showToast('text', res.msg)
            }
        })
    },
    /**
     * 邀请参加招聘会
     */
    invitationFn() {
        if (app.globalData.companState == 0) {
            wx.navigateTo({
                url: `/pages/web/web?url=${app.globalData.WEBURL}/h5/index/weiRenZhengJianLi`
            })
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            user_id: this.data.userId
        }
        ajaxPost('/authuser/Invitation', data, res => {
            if (res.code == 0) {
                showToast('text', '邀请成功')
                this.setData({
                    is_invitation: 1
                })
            } else {
                showToast('text', res.msg)
            }
        })
    },
    /**
     * 有意向
     */
    resumeFn(e) {
        let data = {
            token: wx.getStorageSync('token'),
            resume_position_id: this.data.resume_position_id,
            status: e.currentTarget.dataset.type
        }
        ajaxPost('/authuser/xxsignresume', data, res => {
            if (res.code == 0) {
                showToast('text', '操作成功')
                this.setData({
                    resume_status: e.currentTarget.dataset.type
                })
            } else {
                showToast('text', res.msg)
            }
        })
    },
    /**
     * 记录备注
     */
    saveRemark(e) {
        if (!this.data.remark || this.data.XXuserSource.remark == this.data.remark) {
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            resume_position_id: this.data.resume_position_id,
            remark: this.data.remark
        }
        ajaxPost('/authuser/remarkresume', data, res => {
            if (res.code == 0) {
                showToast('text', '保存成功')
            } else {
                showToast('text', res.msg)
            }
        })
    },
    /**
     * 举报控制
     */
    complaintClick() {
        this.setData({
            complaintShow: true
        })
    },
    // 获取remark
    getRemark(e) {
        this.setData({
            remark: e.detail.value
        })
    },

})